package org.misalen.web.admin.controllers;

import java.util.List;

import org.misalen.web.admin.util.ServerResult;
import org.misalen.web.database.model.mysql.pro.ProDriverLocation;
import org.misalen.web.database.model.mysql.pro.ProDriverUser;
import org.misalen.web.database.repository.mysql.ProDriverUserRepository;
import org.misalen.web.database.util.PaginationFrom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/pro-driver-user")
public class ProDriverUserController extends BaseController {

	@Autowired
	protected ProDriverUserRepository proDriverUserRepository;

	/**
	 * 列表页
	 * 
	 * @return 列表目标页
	 */
	@RequestMapping(value = "/", method = { RequestMethod.GET })
	public ModelAndView list() {
		ModelAndView modelAndView = new ModelAndView("/proDriverUser/list");
		return modelAndView;
	}
	/**
	 * 列表页
	 * 
	 * @return 列表目标页
	 */
	@RequestMapping(value = "/map/", method = { RequestMethod.GET })
	public ModelAndView map() {
		ModelAndView modelAndView = new ModelAndView("/proDriverUser/map");
		modelAndView.addObject("belongCity", getShiroUser().getBelongCity());
		return modelAndView;
	}
	/**
	 * 列表
	 * 
	 * @param 搜索条件
	 * @param 分页/排序条件
	 * @return 查询结果
	 */
	@RequestMapping(value = "/", method = { RequestMethod.POST })
	public @ResponseBody ServerResult listPost(ProDriverUser proDriverUser, PaginationFrom<ProDriverUser> pagination) {
		String belongCity = getShiroUser().getBelongCity();
		if(!belongCity.equals("全国")) {
			proDriverUser.setBelongCity(belongCity);
		}
		PaginationFrom<ProDriverUser> from = proDriverUserRepository.findPageByBean(proDriverUser, pagination);
		return renderSuccess(from);
	}
	
	/**
	 * 列表
	 * 
	 * @param 搜索条件
	 * @param 分页/排序条件
	 * @return 查询结果
	 */
	@RequestMapping(value = "/map/", method = { RequestMethod.POST })
	public @ResponseBody ServerResult mapPost() {
		List<ProDriverLocation> from = proDriverLocationRepository.findAllLocation();
		return renderSuccess(from);
	}
	
}
